<?php
/**
 * Autor:   Miguel A. Zilli
 * Email:   miguelzilli@gmail.com
 */

class Actividadtipo extends AppModel {
    var $name = 'Actividadtipo';
    var $useTable = 'actividadtipos';
    var $primaryKey = 'id';
    var $displayField = 'tipo_act';
    var $recursive = 0;
    var $order=array(
        'Actividadtipo.tipo_act'=>'ASC'
    );

    var $validate = array(
         'tipo_act'=>array(
            array('rule'=>'isUnique','message'=>'Error: Item existente.'),
            array('rule'=>'notEmpty','message'=>'Debe completar este dato.','required'=>true)
        )
    );

    //The Associations below have been created with all possible keys, those that are not needed can be removed
    var $belongsTo = array(
        'Actsupertipo' => array(
            'className' => 'Actsupertipo',
            'foreignKey' => 'actsupertipo_id'
        )
    );

    var $hasMany = array(
        'Producto' => array(
            'className' => 'Producto',
            'foreignKey' => 'actividadtipo_id',
            'limit'=>'0',
            'dependent' => false
        ),
        'Revision' => array(
            'className' => 'Revision',
            'foreignKey' => 'actividadtipo_id',
            'dependent' => false
        )
    );

	var $hasAndBelongsToMany = array(
		'Productor' => array(
			'className' => 'Productor',
			'joinTable' => 'actividadtipos_productores',
			'foreignKey' => 'actividadtipo_id',
			'associationForeignKey' => 'productor_id',
			'unique' => true,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'finderQuery' => '',
			'deleteQuery' => '',
			'insertQuery' => ''
		)
	);

    public function beforeSave(){
        if(!empty($this->data['Actividadtipo'])){
            foreach($this->data['Actividadtipo'] as $campo=>$valor){
                $this->data['Actividadtipo'][$campo]=strtoupper($valor);
            }
        }
        return true;
    }
}
?>
